package com.qf.service.impl;

import com.qf.dao.AddressDao;
import com.qf.dao.impl.AddressDaoImpl;
import com.qf.entity.Address;
import com.qf.service.AddressService;

import java.sql.SQLException;
import java.util.List;

/**
 * @Author:YuhuaZhang
 * @Description
 * @Date:Created in 17:30 2021/11/5
 * @Modified By:
 */
public class AddressServiceImpl implements AddressService {
    @Override
    public List<Address> findAddressByUid(int uid) throws SQLException {

        AddressDao addressDao=new AddressDaoImpl();
        List<Address> list=addressDao.selectAddressByUid(uid);

        return list;
    }

    @Override
    public void saveAddress(Address address) throws SQLException {
        AddressDao addressDao=new AddressDaoImpl();
        addressDao.insertAddress(address);
    }

    @Override
    public void deleteAddressByAid(String aid) throws SQLException {
        AddressDao addressDao=new AddressDaoImpl();
        addressDao.deleteAddressByAid(aid);
    }

    @Override
    public void setAddressToDefault(String aid, int uid) throws SQLException {
        AddressDao addressDao=new AddressDaoImpl();

        //1.将aid的状态改为1-->默认地址
        addressDao.updateAddressToDefault(aid);
        //2.将非aid状态改为0-->非默认地址
        addressDao.updateAddressToCommons(aid,uid);
    }

    @Override
    public void updateAddressByAid(Address address) throws SQLException {
        AddressDao addressDao=new AddressDaoImpl();
        addressDao.updateAddressByAid(address);
    }
}
